/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import model.entities.Account;
import model.entities.Book;
import model.entities.Comment;

/**
 *
 * @author HoangTien
 */
public class SqlComment {
    MyConnection mc = new MyConnection();
    Comment comment;
    
    public int createComment(int bId,String uname, String title, String content) {
        List para = new ArrayList();
        para.add(bId);
        para.add(uname);
        para.add(title);
        para.add(content);
        try {
            return mc.executeUpdate("sp_comment", para);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }
    
    public List<Comment> getListComment(int bookId) {
        List<Comment> data = new ArrayList<Comment>();
        List para = new ArrayList();
        para.add(bookId);
        try {
            ResultSet rs = mc.executeQuery("sp_get_comment_by_bookId", para);
            while (rs.next()) {                
                comment = new Comment(rs.getInt(1), rs.getInt(2), rs.getString(3), 
                        rs.getString(4), rs.getString(5));
                data.add(comment);
            }
        } catch (SQLException e) {
            System.out.println("SqlComment::getListComment::SQLException");
        }
        return data;
    }
    
}
